const Koa = require('koa')
const views = require('koa-views')
const path = require('path')
const app = new Koa()
const Router = require('koa-router')
const static = require('koa-static')

// 加载模板引擎
app.use(views(path.join(__dirname, './'), {
  extension: 'ejs'
}))

// 静态资源目录对于相对入口文件index.js的路径
const staticPath = static(path.join('./image'))

// 装载所有子路由
let router = new Router()

// 子路由1
router.get('/home',  async( ctx, next )=>{

    let title = 'hello koa2'
    await ctx.render('travel', {
        title,
    })

})

router.get('/', async (ctx, next) => {
    ctx.response.body = '<h1>Index</h1>';
});


app.use(staticPath)

// 加载路由中间件
app.use(router.routes()).use(router.allowedMethods())

app.listen(3000)